using System;
using System.Xml;
using EstudoMono.Utils.entidades.Pergunta;

namespace EstudoMono.Utils
{
	public class XmlFileManger
	{
		public XmlFileManger ()
		{
			
		}


		public void ReadXMLFile (string xmlPath)
		{
			XmlTextReader reader = new XmlTextReader (xmlPath);
			
			while (reader.Read ()) {
				switch (reader.NodeType) {
				case XmlNodeType.Element:
					// The node is an element.
					if (reader.Name.Equals ("categoria")) {
						Console.WriteLine (reader.Name.ToString ());
						reader.Read ();
						reader.Read ();
						Console.WriteLine (reader.Name.ToString ());
						if (reader.Name.Equals ("perguntas")) {
							
							while (reader.Read ()) {
								//Pergunta p = null;
								string pergunta = String.Empty;
								string resposta1 = String.Empty;
								string resposta2 = String.Empty;
								string resposta3 = String.Empty;
								string resposta4 = String.Empty;
								string correta = String.Empty;
								
								if (reader.Name.Equals ("pergunta")) {
									while (reader.Read ()) {
										
										if (reader.AttributeCount > 0) {
											if (reader.GetAttribute ("resposta").ToString ().Equals ("s"))
												correta = reader.ReadString ();
										}
										
										switch (reader.Name) {
										case "texto":
											pergunta = reader.ReadString ();
											break;
										
										case "a":
											resposta1 = reader.ReadString ();
											break;
										
										case "b":
											resposta2 = reader.ReadString ();
											break;
										
										case "c":
											resposta3 = reader.ReadString ();
											break;
										
										case "d":
											resposta4 = reader.ReadString ();
											/*p = new Pergunta (pergunta, resposta1, resposta2, resposta3, resposta4, correta);
											perguntas.Add (p);
											Console.WriteLine (perguntas.Count);*/
											break;
										}
										
										
									}
									
								}
							}
						}
					}
					break;
					
				}
				Console.ReadLine ();
			}
		}
	}
}

